package com.song.dubbo3consumer.filter;

import com.song.dubbo3consumer.config.TraceUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;


/**
 * @Author SHI YUAN
 * @DATE 2022/2/8 2:04 PM
 * @Version 1.0
 * @Desc
 */
@Slf4j
@Activate(group = CommonConstants.CONSUMER, order = -1)
public class TradeIdFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String traceId = TraceUtils.getTraceId();
        RpcContext.getClientAttachment().setAttachment("traceId", traceId);
        return invoker.invoke(invocation);
    }
}
